package com.iot.ic.service;

import com.iot.ic.common.Constant;
import com.iot.ic.common.Response;
import com.iot.ic.dao.LocationMapper;
import com.iot.ic.dao.TeamLocationMapper;
import com.iot.ic.model.Device;
import com.iot.ic.model.Location;
import com.iot.ic.model.TeamInfo;
import com.iot.ic.model.TeamLocation;
import com.iot.ic.tcp.model.Point;
import com.iot.ic.utils.OkHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiuge on 2017/7/10.
 */
@Service
public class TeamLocationServiceImpl implements TeamLocationService {

    @Autowired
    private TeamLocationMapper teamlocationMapper;

    @Autowired
    private TeamService teamService;
    

    @Autowired
	SimpMessagingTemplate simpMessagingTemplate;


    Logger logger= LoggerFactory.getLogger(TeamLocationServiceImpl.class);

	@Override
	public int addLocationHistory(TeamLocation teamLocation) {
		TeamInfo teamInfo = teamService.getTeam(teamLocation.getTeamId());
		if (teamInfo != null) {
			teamLocation.setTeamState(teamInfo.getTeamState());
		}
		int result = teamlocationMapper.insert(teamLocation);
		//websocket推送
//	    if (result == 1) {
//		    Response response = new Response();
//		    List<TeamLocation> teamLocations = teamlocationMapper.findTeamLocationList(teamLocation);
//		    response.setResult(teamLocations);
//		    simpMessagingTemplate.convertAndSend("/topic/testLocationsocketpush", response);
//	    }
		
		return result;
	}

	@Override
	public List<TeamLocation> listTeamLocations(TeamLocation teamLocation) {
		List<TeamLocation> teamLocations = teamlocationMapper.findTeamLocationList(teamLocation);
		return teamLocations;
	}


  


}
